package springbootdemo.control;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springbootdemo.entity.Person;
import springbootdemo.entity.Person1;
import springbootdemo.service.DemoService;

/**
 * :@RestController Spring4 之后新加的注解,原来返回json需要@ResponseBody配合@Controller,现在一个顶俩
 */
@RestController
//@EnableAutoConfiguration
//@RequestMapping(value = "/demo", produces = "application/json;charset=UTF-8")
@RequestMapping("/demo")
public class HelloController {
    //获取application.yml中的值
    @Value("${name}")
    private String name;
    @Value("${arr}")
    private String arr[];
    @Value("${testYml.arr}")
    private String arr1[];
    //list不能直接这样读取
    //@Value("${list}")
    //private ArrayList list;
    @Value("${testTime}")
    private Date testTime;
    @Value("${person.age}")
    private String age;
    @Value("${person.sal}")
    private Integer sal;
    @Autowired//需要注解才能引入
    private Person person;

    @Autowired//需要注解才能引入
    private Person1 person1;

    //如果配置文件中没有设置 ggg, spring在启动的时候会报错。这时需要给name配置默认值
    @Value("${ggg:hmp}")
    private String ggg;

    @Resource
    private DemoService demoService;

    @RequestMapping("/hello")
    public String say() {
        System.out.println("==================" + name);
        System.out.println(Arrays.toString(arr));
        System.out.println(Arrays.toString(arr1));
        System.out.println(testTime);
        System.out.println(age);
        System.out.println(sal);
        System.out.println(person);
        System.out.println(person1);
        return name + "," + "ri热部署哈哈Hello SpringBoot!";
    }

    @RequestMapping("/test")
    public List test() {
        return  demoService.getList();
    }
}
